﻿
function chaoMung() {
    alert('chao mung');
}

function xemBangTin() {
    alert('bang tin');
}

function xemTinNhan() {
    alert('tin nhan');
}

function xemAlbumAnh() {
    alert('album anh');
}

function xemBanBe() {
    alert('ban be');
}

function dangBinhLuan(text) {
    var t = text.val();
    var p = text.parent().parent().find('.binhLuan');
    var div = '<div>' +
            '<div style="width:15px;float:left">' +
                '<img alt="..." src="../../Images/onl.png" width="15px" height="15px"/>' +
            '</div>' +
            '<div style="margin:3px 0 0 5px;float:left;word-wrap:break-word">' + t + '</div>' +
            '<div class="clear"></div>' +
        '</div>';
    p.append(div);
    text.val('');
}

function dangTrangThai(text) {
    //lay cai id
    var id = 2;
    var s = '<div id="bai-#{id}" style="margin:20px">' +
                '<div style="float:left;width:50px">' +
                    '<img alt="..." src="../../Images/onl.png" width="50" height="50" />' +
                '</div>' +
                '<div style="float:left;width:490px">' +
                    '<a href="javascript:void(0)" style="margin:0 0 0 10px;font-family:\'Times New Roman\';' +
                        'font-size:11pt;font-weight:bold;text-decoration:none">' +
                        'get name cua minh</a>' +
                    '<div style="margin:10px 0 0 10px">#{noiDungBinhLuan}</div>' +
                    '<div>' +
                        '<div class="binhLuan" style="word-wrap:break-word"></div>' +
                        '<div style="float:left;width:35px">' +
                            '<img alt="..." src="../../Images/onl.png" width="35" height="35" />' +
                        '</div>' +
                        '<div>' +
                            '<textarea style="width:85%;overflow:hidden;resize:none;height:20px;' +
                                'font-family:Tahoma;font-size:10pt;margin:5px 0 0 10px" name="txtBinhLuan" id="txtBinhLuan-#{id}"' +
                                'onkeyup="javascript:fitHeightToContent(this.id);"></textarea>' +
                        '</div>' +
                        '<div class="clear"></div>' +
                    '</div>' +
                 '</div>' +
                 '<div class="clear"></div>' +
            '</div>';
    var div = $(s.replace(/#\{noiDungBinhLuan\}/g, text.val()).replace(/#\{id\}/g, id));
    $('#baiDangs').append(div);
    text.val('');
}

function fitHeightToContent(id) {
    var txt = document.getElementById(id);
    var h = txt.scrollHeight;
    txt.style.height = 'auto';
    txt.style.height = txt.scrollHeight + 'px';
}



$(document).ready(function () {

    $('#bnChaoMung').click(function () {
        chaoMung();
    });

    $('#bnBangTin').click(function () {
        xemBangTin();
    });

    $('#bnTinNhan').click(function () {
        xemTinNhan();
    });

    $('#bnAlbumAnh').click(function () {
        xemAlbumAnh();
    });

    $('#bnBanBe').click(function () {
        xemBanBe();
    });

    $('#divCaNhan').click(function () {
        xemTrangCaNhan();
    });

    $('textarea[name=txtBinhLuan]').live('keypress', function (e) {
        if (e.keyCode == 13) {
            dangBinhLuan($(this));
            e.preventDefault();
        }
    });

    $('#bnDangTrangThai').click(function () {
        dangTrangThai($(this).parent().parent().parent().find('#txtTrangThai'));
    });;
});



function onFriendsListLoaded(response) {
    var divTarget = document.getElementById("friends-list-container");
    var data = response.data;
    //alert("divTarget="+divTarget+"\ndata="+data);
    for (var friendIndex = 0; friendIndex < data.length; friendIndex++) {
        var divContainer = document.createElement("div");
        divContainer.innerHTML = "<hr><img src='http://graph.facebook.com/" + data[friendIndex].id + "/picture'></img>" +
                "<br>" + data[friendIndex].name;
        divTarget.appendChild(divContainer);
    }
}

function showFriendsList() {
    FB.api('/me/friends', onFriendsListLoaded);
}